package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Phone     string `grom:"type;varchar(30)"`
	Password  string `grom:"type;varchar(255)"`
	HeadImage string `grom:"type;varchar(500)"`
	NickName  string `grom:"type;varchar(30)"`
}

func (u *User) UserFirstOrCreate(db *gorm.DB, phone string) error {
	return db.Debug().Where("phone=?", phone).FirstOrCreate(u).Error
}

func (u *User) FindUserByPhone(db *gorm.DB, phone string) error {
	return db.Debug().Where("phone=?", phone).First(u).Error
}

func (u *User) UserPassword(db *gorm.DB, phone string) error {
	return db.Debug().Where("phone=?", phone).Updates(u).Error
}

func (u *User) FindUserByUserId(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).First(u).Error
}
